var winston = require('winston');

var mongodb = require('winston-mongodb').MongoDB;

var logger = new (winston.Logger)({
	transports: [
	    new (winston.transports.Console)(),
	    new (winston.transports.File)({filename: __dirname + '/log/talkalive.log'}),
	    new (winston.transports.MongoDB)({db: 'muchine', collection: 'logs', host: 'db.304lab.net', port: 27017})
	]
});

exports.logger = logger;

/*
 * get location of cell based on it's id
 */
exports.getLocation = function(id) {
	coord = id.split('x');
	var x = Number(coord[0].replace('g', ''));
	var y = Number(coord[1].replace('y', ''));
	
	return {id: id, x: x, y: y};
};

/*
 * return boolean value that represents whether the location is near the center or not
 */
exports.isNear = function(center, location) {
	if (center && location) {
		if (Math.abs(location.x - center.x) <= 64 && Math.abs(location.y - center.y)  <= 24) {
			return true;
		}	
	}

	return false;
};